deploy/libmount: Fix build with old util-linux 2.23 (CentOS7)
authorColin Walters <walters@verbum.org>
Fri, 24 Feb 2017 15:18:27 +0000 (10:18 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 24 Feb 2017 17:24:15 +0000 (17:24 +0000)
https://github.com/ostreedev/ostree/pull/705 broke the build
on CentOS 7 which only has util-linux 2.23.

When I was thinking about this, I realized that there must really be a way to
make this safe even for older versions. Looking at that version of util-linux,
all we need to do is invert the order of frees so we `mnt_free_table()` *before*
`mnt_free_cache()`, like util-linux does:

https://github.com/karelzak/util-linux/blob/stable/v2.23/sys-utils/eject.c#L1131

We still use the `_unref()` versions if available.  I also fixed
the ordering there too for double plus redundant safety.

Closes: #712
Approved by: jlebon

configure.ac
src/libostree/ostree-sysroot-deploy.c

index 979d8ccb7ccabea85a24a5fd0103f876d4aeb599..48d8949c65331c5c03c3129974b84ebf2e04b918 100644 (file)
@@ -299,6 +299,10 @@ AS_IF([ test x$with_libmount != xno ], [
         AC_DEFINE([HAVE_LIBMOUNT], 1, [Define if we have libmount.pc])
        PKG_CHECK_MODULES(OT_DEP_LIBMOUNT, $LIBMOUNT_DEPENDENCY)
        with_libmount=yes
+  save_LIBS=$LIBS
+  LIBS=$OT_DEP_LIBMOUNT_LIBS
+  AC_CHECK_FUNCS(mnt_unref_cache)
+  LIBS=$save_LIBS
     ], [
        with_libmount=no
     ])
index 5a3f6d855fa9bab00a6cfba43bbf9b39ac6c7523..1cfe6ab1fdf7b2bc741465905834833e69fdb05b 100644 (file)
@@ -1692,8 +1692,13 @@ is_ro_mount (const char *path)
 
   fs = mnt_table_find_target(tb, path, MNT_ITER_BACKWARD);
   is_mount = fs && mnt_fs_get_target (fs);
-  mnt_unref_cache (cache);
+#ifdef HAVE_MNT_UNREF_CACHE
   mnt_unref_table (tb);
+  mnt_unref_cache (cache);
+#else
+  mnt_free_table (tb);
+  mnt_free_cache (cache);
+#endif
 
   if (!is_mount)
     return FALSE;